#pragma once

#include "problem_solver.h"
#include <iostream>

namespace solver {

	class problem_render
	{
	public:
		void render_html(std::ofstream& hout, solver::problem_solver* problem_solver, solver::istrategy& strategy)
		{
			hout << R"(
<html>
<head>
</head>
<style type="text/css">
h2 {
font-family:Arial;
font-size:14px;
border-bottom:1px solid black;
}
td {
font-family:Consolas,Courier-New;
font-size:12px;
border-left:1px solid #c0c0c0;
vertical-align:top;
}
th {
font-family:Arial;
background-color:#c0c0c0;
padding:4px;
font-size:12px;
vertical-align:top;
}
table {
border-collapse:collapse;
border:1px solid #c0c0c0;
width:100%;
}
</style>
<body>
<h2>OverSATC Problem: )";

			hout << problem_solver->problem_name.c_str();
			
			hout << R"(</h2>
				)";

			for (int id = 0; id < problem_solver->decisions.size(); id++)
			{
				auto d = problem_solver->decisions[id];
				strategy.write_decision_html(hout, problem_solver, *d);

				if (id < problem_solver->decisions.size() - 1) {
					hout << " &and; ";
				}
			}

			hout << R"(<br/>)";

			hout << R"(<h2>Solution</h2>)" << std::endl;

			if (problem_solver->solved)
			{
				hout << R"(<pre>Solved</pre>)" << std::endl;
			}
			else 
			{
				hout << R"(<pre>Not Solved</pre>)" << std::endl;
			}

			hout << R"(<p>)";
			bool had_errors = false;
			for (auto dc : problem_solver->solution)
			{
				auto& vi = problem_solver->variables[dc.lit.ref];
				if (!vi.check_valid) 
				{
					had_errors = true;
					hout << R"(<span style="color:red">)";
				}
				if (vi.value)
				{
					hout << " " << vi.name;
				}
				else
				{
					hout << " " << -vi.name;
				}
				if (!vi.check_valid)
				{
					had_errors = true;
					hout << R"( Wrong </span>)";
				}
			}
			hout << R"(</p>)";
			if (had_errors) {
				hout << R"(<p>Solution is Incorrect</p>)";
			}
			else {
				hout << R"(<p>Solution is Correct</p>)";
			}

			hout << R"(<h2>Comments</h2>)" << std::endl;
			hout << R"(<pre>)" << std::endl;
			hout << problem_solver->comments.c_str() << std::endl;
			hout << R"(</pre)" << std::endl;

			hout << R"(
			</body>
				</html>
)";
		}

	};

}
